import request from '@/utils/request'

// 查询列表
export function listOssByIds(ossIds) {
  return request({
    url: '/system/oss/query/' + ossIds,
    method: 'get'
  });
}

export function queryOssById(ossId) {
  if (ossId === undefined || ossId === null) {
    return ;
  }
  return request({
    url: '/system/oss/query',
    params: {
      id: ossId
    },
    method: 'get'
  })
}

// 根据传入的id下载文件
export function downloadFileById(ossId, filename) {
  request({
    url: '/system/oss/download',
    method: 'get',
    params: {
      templateFile: ossId
    },
    responseType: 'blob'
  }).then(response => {
    let url = window.URL.createObjectURL(response); // 创建 url 并指向 blob
    let a = document.createElement('a');
    a.href = url;
    a.download = filename !== undefined? filename: ossId;
    a.click();
    window.URL.revokeObjectURL(url); // 释放该 url
  });
}
